package com.varian.tool.exception;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.varian.tool.contant.ResultConstant;

/**
 * @author ben
 * @since 2024/6/22
 */
public class ServerException extends BaseException {

    protected ServerException() {
        this(ResultConstant.SERVICE_ERROR.message());
    }

    protected ServerException(String message) {
        this(ResultConstant.SERVICE_ERROR.status(), message);
    }

    protected ServerException(Integer status, String message) {
        super(status, message);
    }

    public static ServerException of() {
        return new ServerException();
    }

    public static ServerException of(String message, Object... args) {
        return of(StrUtil.format(message, args));
    }

    public static ServerException of(String message) {
        return new ServerException(message);
    }

    public static ServerException of(Integer status, String message, Object... args) {
        return of(status, StrUtil.format(message, args));
    }

    public static ServerException of(Integer status, String message) {
        return new ServerException(status, message);
    }

    @Override
    public StackTraceElement[] getStackTrace() {
        return ArrayUtil.sub(super.getStackTrace(), 0, 5);
    }
}
